/*
Copyright (c) 2008 salesforce.com, inc.
All rights reserved.
  
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/



/* reference for this class is best found on Amazon developer site 
 * 
 *  http://docs.amazonwebservices.com/AmazonS3/latest/
 
 * example of connector class to send and retrieve data from Amazon S3 using SOAP
 * after install, you must add https://s3.amazonaws.com to your remote site access list 
 * and set key and secret values into the Apex Class AWSKeys
 */
 
 
 /*
     Additioal information: This code was generated by the WSDL2Apex functionality within the force.com platform. 
     	The code that is commented out has not yet been implemented in this version of the Force.com Toolkit for Amazon Web Services.
   		The code was purposely left in this Apex Class for developers to enable, if needed for their solution.  
 */
 
 
public class S3 {
  /* public class LoggingSettings {
        public String TargetBucket;
        public String TargetPrefix;
        public S3.AccessControlList TargetGrants;
        private String[] TargetBucket_type_info = new String[]{'TargetBucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] TargetPrefix_type_info = new String[]{'TargetPrefix','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] TargetGrants_type_info = new String[]{'TargetGrants','http://s3.amazonaws.com/doc/2006-03-01/','AccessControlList','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'TargetBucket','TargetPrefix','TargetGrants'};
    }
    */
   /* 
   public class Grant {
        public S3.Grantee Grantee;
        public String Permission;
        private String[] Grantee_type_info = new String[]{'Grantee','http://s3.amazonaws.com/doc/2006-03-01/','Grantee','1','1','false'};
        private String[] Permission_type_info = new String[]{'Permission','http://s3.amazonaws.com/doc/2006-03-01/','Permission','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Grantee','Permission'};
    }
    */
    public class ListBucketResponse_element {
        public S3.ListBucketResult ListBucketResponse;
        private String[] ListBucketResponse_type_info = new String[]{'ListBucketResponse','http://s3.amazonaws.com/doc/2006-03-01/','ListBucketResult','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'ListBucketResponse'};
    }
    public class ListBucketResult {
        public S3.MetadataEntry[] Metadata { get; set; }
        public String Name {get;set;} //added by davidv
        public String Prefix;
        public String Marker;
        public String NextMarker;
        public Integer MaxKeys;
        public String Delimiter;
        public Boolean IsTruncated;
        public S3.ListEntry[] Contents;
        public S3.PrefixEntry[] CommonPrefixes;
        private String[] Metadata_type_info = new String[]{'Metadata','http://s3.amazonaws.com/doc/2006-03-01/','MetadataEntry','0','-1','false'};
        private String[] Name_type_info = new String[]{'Name','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Prefix_type_info = new String[]{'Prefix','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Marker_type_info = new String[]{'Marker','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] NextMarker_type_info = new String[]{'NextMarker','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] MaxKeys_type_info = new String[]{'MaxKeys','http://www.w3.org/2001/XMLSchema','int','1','1','false'};
        private String[] Delimiter_type_info = new String[]{'Delimiter','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] IsTruncated_type_info = new String[]{'IsTruncated','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
        private String[] Contents_type_info = new String[]{'Contents','http://s3.amazonaws.com/doc/2006-03-01/','ListEntry','0','-1','false'};
        private String[] CommonPrefixes_type_info = new String[]{'CommonPrefixes','http://s3.amazonaws.com/doc/2006-03-01/','PrefixEntry','0','-1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Metadata','Name','Prefix','Marker','NextMarker','MaxKeys','Delimiter','IsTruncated','Contents','CommonPrefixes'};
    }
   /*
    public class CopyObjectResult {
        public DateTime LastModified;
        public String ETag;
        private String[] LastModified_type_info = new String[]{'LastModified','http://www.w3.org/2001/XMLSchema','dateTime','1','1','false'};
        private String[] ETag_type_info = new String[]{'ETag','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'LastModified','ETag'};
    }
    
    */
    
    
    public class ListAllMyBucketsList {
        public S3.ListAllMyBucketsEntry[] Bucket {get;set;}
        private String[] Bucket_type_info = new String[]{'Bucket','http://s3.amazonaws.com/doc/2006-03-01/','ListAllMyBucketsEntry','0','-1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket'};
    }
    
    
    public class MetadataEntry {
        public String Name {get; set;}
        public String Value;
        private String[] Name_type_info = new String[]{'Name','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Value_type_info = new String[]{'Value','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Name','Value'};
    }
    /*
    public class GetBucketAccessControlPolicyResponse_element {
        public S3.AccessControlPolicy GetBucketAccessControlPolicyResponse;
        private String[] GetBucketAccessControlPolicyResponse_type_info = new String[]{'GetBucketAccessControlPolicyResponse','http://s3.amazonaws.com/doc/2006-03-01/','AccessControlPolicy','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'GetBucketAccessControlPolicyResponse'};
    }
    public class GetObjectResponse_element {
        public S3.GetObjectResult GetObjectResponse;
        private String[] GetObjectResponse_type_info = new String[]{'GetObjectResponse','http://s3.amazonaws.com/doc/2006-03-01/','GetObjectResult','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'GetObjectResponse'};
    }
    
    */
    
    
    /*
     	This inner class, AmazonS3, contains the methods that invoke the Web Service calls to Amazon Web Services. 
     	
    */
    
    public class AmazonS3 {
    	public AmazonS3(String key, String secret){
    	    this.key = key;
    	    this.secret= secret;	
    	}
    	
    	public AmazonS3(){
    		
    	}
    	
    	/*
    	  Per the AWS S3 documentation: 
    	  	The RFC 2104 HMAC-SHA1 digest (go to http://www.ietf.org/rfc/rfc2104.txt) of the 
    	  	concatenation of "AmazonS3" + OPERATION + Timestamp, using your AWS Secret Access Key as the key. 
    	*/
	    public string signature( string op, Datetime now) {
			//format should be  2006-01-01T12:00:00.000Z
			system.assert( this.secret != null ,' missing S3.secret key');
	        String formattednow = now.formatGmt('yyyy-MM-dd')+'T'+now.formatGmt('HH:mm:ss')+'.'+now.formatGMT('SSS')+'Z';           
	        String canonical = 'AmazonS3'+op+formattednow; //"AmazonS3" + OPERATION + Timestamp              
	        Blob bsig = Crypto.generateMac('HmacSHA1', Blob.valueOf(canonical), Blob.valueOf(this.secret));          
	        return EncodingUtil.base64Encode(bsig); 
		}
		
		
		public string secret { get; set; }
		public string key { get; set; }
	    public String endpoint_x = 'https://s3.amazonaws.com/soap';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        private String[] ns_map_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/', 'S3'};
      
      /*
        public void SetBucketLoggingStatus(String Bucket,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential,S3.BucketLoggingStatus BucketLoggingStatus) {
            S3.SetBucketLoggingStatus_element request_x = new S3.SetBucketLoggingStatus_element();
            S3.SetBucketLoggingStatusResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            request_x.BucketLoggingStatus = BucketLoggingStatus;
            Map<String, S3.SetBucketLoggingStatusResponse_element> response_map_x = new Map<String, S3.SetBucketLoggingStatusResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'SetBucketLoggingStatus',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'SetBucketLoggingStatusResponse',
              'S3.SetBucketLoggingStatusResponse_element'}
            );
            response_x = response_map_x.get('response_x');
        }
        
        */
        
        /*
        public S3.GetObjectResult GetObject(String Bucket,String Key,Boolean GetMetadata,Boolean GetData,Boolean InlineData,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential) {
            S3.GetObject_element request_x = new S3.GetObject_element();
            S3.GetObjectResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.Key = Key;
            request_x.GetMetadata = GetMetadata;
            request_x.GetData = GetData;
            request_x.InlineData = InlineData;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            Map<String, S3.GetObjectResponse_element> response_map_x = new Map<String, S3.GetObjectResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'GetObject',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'GetObjectResponse',
              'S3.GetObjectResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.GetObjectResponse;
        }
        */
        
        
        /*
           This method invokes the S3 DeleteObject web service operation.
        */
        public S3.Status DeleteObject(String Bucket,String Key,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential) {
            S3.DeleteObject_element request_x = new S3.DeleteObject_element();
            S3.DeleteObjectResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.Key = Key;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            Map<String, S3.DeleteObjectResponse_element> response_map_x = new Map<String, S3.DeleteObjectResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'DeleteObject',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'DeleteObjectResponse',
              'S3.DeleteObjectResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.DeleteObjectResponse;
        }
        
        /*
           This method invokes the S3 ListBucket web service operation.
        */
        public S3.ListBucketResult ListBucket(String Bucket,String Prefix,String Marker,Integer MaxKeys,String Delimiter,String AWSAccessKeyId,DateTime Timestamp,String Signature, String Credential) {
            S3.ListBucket_element request_x = new S3.ListBucket_element();
            S3.ListBucketResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.Prefix = Prefix; 
            request_x.Marker = Marker;
            request_x.MaxKeys = MaxKeys;
            request_x.Delimiter = Delimiter;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            Map<String, S3.ListBucketResponse_element> response_map_x = new Map<String, S3.ListBucketResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'ListBucket',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'ListBucketResponse',
              'S3.ListBucketResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.ListBucketResponse;
        }
        
        
        /*
           This method invokes the S3 ListAllMyBuckets web service operation.
        */
        public S3.ListAllMyBucketsResult ListAllMyBuckets(String AWSAccessKeyId,DateTime Timestamp,String Signature) {
            S3.ListAllMyBuckets_element request_x = new S3.ListAllMyBuckets_element();
            S3.ListAllMyBucketsResponse_element response_x;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            Map<String, S3.ListAllMyBucketsResponse_element> response_map_x = new Map<String, S3.ListAllMyBucketsResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'ListAllMyBuckets',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'ListAllMyBucketsResponse',
              'S3.ListAllMyBucketsResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.ListAllMyBucketsResponse;
        }
        
        /*
        public S3.BucketLoggingStatus GetBucketLoggingStatus(String Bucket,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential) {
            S3.GetBucketLoggingStatus_element request_x = new S3.GetBucketLoggingStatus_element();
            S3.GetBucketLoggingStatusResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            Map<String, S3.GetBucketLoggingStatusResponse_element> response_map_x = new Map<String, S3.GetBucketLoggingStatusResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'GetBucketLoggingStatus',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'GetBucketLoggingStatusResponse',
              'S3.GetBucketLoggingStatusResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.GetBucketLoggingStatusResponse;
        }
        */
        
        /*
           This method invokes the S3 CreateBucket web service operation.
        */
        public S3.CreateBucketResult CreateBucket(String Bucket,S3.AccessControlList AccessControlList,String AWSAccessKeyId,DateTime Timestamp,String Signature) {
            S3.CreateBucket_element request_x = new S3.CreateBucket_element();
            S3.CreateBucketResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.AccessControlList = AccessControlList;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            Map<String, S3.CreateBucketResponse_element> response_map_x = new Map<String, S3.CreateBucketResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'CreateBucket',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'CreateBucketResponse',
              'S3.CreateBucketResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.CreateBucketResponse;
        }
        
        
        /*
        public S3.AccessControlPolicy GetBucketAccessControlPolicy(String Bucket,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential) {
            S3.GetBucketAccessControlPolicy_element request_x = new S3.GetBucketAccessControlPolicy_element();
            S3.GetBucketAccessControlPolicyResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            Map<String, S3.GetBucketAccessControlPolicyResponse_element> response_map_x = new Map<String, S3.GetBucketAccessControlPolicyResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'GetBucketAccessControlPolicy',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'GetBucketAccessControlPolicyResponse',
              'S3.GetBucketAccessControlPolicyResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.GetBucketAccessControlPolicyResponse;
        }
        
        */
        
        /*
        public void SetBucketAccessControlPolicy(String Bucket,S3.AccessControlList AccessControlList,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential) {
            S3.SetBucketAccessControlPolicy_element request_x = new S3.SetBucketAccessControlPolicy_element();
            S3.SetBucketAccessControlPolicyResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.AccessControlList = AccessControlList;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            Map<String, S3.SetBucketAccessControlPolicyResponse_element> response_map_x = new Map<String, S3.SetBucketAccessControlPolicyResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'SetBucketAccessControlPolicy',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'SetBucketAccessControlPolicyResponse',
              'S3.SetBucketAccessControlPolicyResponse_element'}
            );
            response_x = response_map_x.get('response_x');
        }
        
        */
        
        
        /*
           This method invokes the S3 DeleteBucket web service operation.
        */
        public S3.Status DeleteBucket(String Bucket,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential) {
            S3.DeleteBucket_element request_x = new S3.DeleteBucket_element();
            S3.DeleteBucketResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            Map<String, S3.DeleteBucketResponse_element> response_map_x = new Map<String, S3.DeleteBucketResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'DeleteBucket',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'DeleteBucketResponse',
              'S3.DeleteBucketResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.DeleteBucketResponse;
        }
        
        /*
        public void SetObjectAccessControlPolicy(String Bucket,String Key,S3.AccessControlList AccessControlList,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential) {
            S3.SetObjectAccessControlPolicy_element request_x = new S3.SetObjectAccessControlPolicy_element();
            S3.SetObjectAccessControlPolicyResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.Key = Key;
            request_x.AccessControlList = AccessControlList;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            Map<String, S3.SetObjectAccessControlPolicyResponse_element> response_map_x = new Map<String, S3.SetObjectAccessControlPolicyResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'SetObjectAccessControlPolicy',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'SetObjectAccessControlPolicyResponse',
              'S3.SetObjectAccessControlPolicyResponse_element'}
            );
            response_x = response_map_x.get('response_x');
        }
        
        */
        
        /*
        
        public S3.CopyObjectResult CopyObject(String SourceBucket,String SourceKey,String DestinationBucket,String DestinationKey,String MetadataDirective,S3.MetadataEntry[] Metadata,S3.AccessControlList AccessControlList,DateTime CopySourceIfModifiedSince,DateTime CopySourceIfUnmodifiedSince,String[] CopySourceIfMatch,String[] CopySourceIfNoneMatch,String StorageClass,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential) {
            S3.CopyObject_element request_x = new S3.CopyObject_element();
            S3.CopyObjectResponse_element response_x;
            request_x.SourceBucket = SourceBucket;
            request_x.SourceKey = SourceKey;
            request_x.DestinationBucket = DestinationBucket;
            request_x.DestinationKey = DestinationKey;
            request_x.MetadataDirective = MetadataDirective;
            request_x.Metadata = Metadata;
            request_x.AccessControlList = AccessControlList;
            request_x.CopySourceIfModifiedSince = CopySourceIfModifiedSince;
            request_x.CopySourceIfUnmodifiedSince = CopySourceIfUnmodifiedSince;
            request_x.CopySourceIfMatch = CopySourceIfMatch;
            request_x.CopySourceIfNoneMatch = CopySourceIfNoneMatch;
            request_x.StorageClass = StorageClass;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            Map<String, S3.CopyObjectResponse_element> response_map_x = new Map<String, S3.CopyObjectResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'CopyObject',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'CopyObjectResponse',
              'S3.CopyObjectResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.CopyObjectResult;
        }
        
        */
        
        /*
        public S3.GetObjectResult GetObjectExtended(String Bucket,String Key,Boolean GetMetadata,Boolean GetData,Boolean InlineData,Double ByteRangeStart,Double ByteRangeEnd,DateTime IfModifiedSince,DateTime IfUnmodifiedSince,String[] IfMatch,String[] IfNoneMatch,Boolean ReturnCompleteObjectOnConditionFailure,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential) {
            S3.GetObjectExtended_element request_x = new S3.GetObjectExtended_element();
            S3.GetObjectExtendedResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.Key = Key;
            request_x.GetMetadata = GetMetadata;
            request_x.GetData = GetData;
            request_x.InlineData = InlineData;
            request_x.ByteRangeStart = ByteRangeStart;
            request_x.ByteRangeEnd = ByteRangeEnd;
            request_x.IfModifiedSince = IfModifiedSince;
            request_x.IfUnmodifiedSince = IfUnmodifiedSince;
            request_x.IfMatch = IfMatch;
            request_x.IfNoneMatch = IfNoneMatch;
            request_x.ReturnCompleteObjectOnConditionFailure = ReturnCompleteObjectOnConditionFailure;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            Map<String, S3.GetObjectExtendedResponse_element> response_map_x = new Map<String, S3.GetObjectExtendedResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'GetObjectExtended',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'GetObjectExtendedResponse',
              'S3.GetObjectExtendedResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.GetObjectResponse;
        }
        
        */
        
        /*
        public S3.AccessControlPolicy GetObjectAccessControlPolicy(String Bucket,String Key,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential) {
            S3.GetObjectAccessControlPolicy_element request_x = new S3.GetObjectAccessControlPolicy_element();
            S3.GetObjectAccessControlPolicyResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.Key = Key;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            Map<String, S3.GetObjectAccessControlPolicyResponse_element> response_map_x = new Map<String, S3.GetObjectAccessControlPolicyResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'GetObjectAccessControlPolicy',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'GetObjectAccessControlPolicyResponse',
              'S3.GetObjectAccessControlPolicyResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.GetObjectAccessControlPolicyResponse;
        }
        
        */
        
        /*
        public S3.PutObjectResult PutObject(String Bucket,String Key,S3.MetadataEntry[] Metadata,Double ContentLength,S3.AccessControlList AccessControlList,String StorageClass,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential) {
            S3.PutObject_element request_x = new S3.PutObject_element();
            S3.PutObjectResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.Key = Key;
            request_x.Metadata = Metadata;
            request_x.ContentLength = ContentLength;
            request_x.AccessControlList = AccessControlList;
            request_x.StorageClass = StorageClass;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            Map<String, S3.PutObjectResponse_element> response_map_x = new Map<String, S3.PutObjectResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'PutObject',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'PutObjectResponse',
              'S3.PutObjectResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.PutObjectResponse;
        }
        
        */
        
        
        public S3.PutObjectResult PutObjectInline(String Bucket,String Key,S3.MetadataEntry[] Metadata,String Data,Double ContentLength,S3.AccessControlList AccessControlList,String StorageClass,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential) {
            S3.PutObjectInline_element request_x = new S3.PutObjectInline_element();
            S3.PutObjectInlineResponse_element response_x;
            request_x.Bucket = Bucket;
            request_x.Key = Key;
            request_x.Metadata = Metadata;
            request_x.Data = Data;
            System.debug('TESTContentLength: ' +ContentLength.intValue());
            request_x.ContentLength = ContentLength.intValue();
            request_x.AccessControlList = AccessControlList;
            request_x.StorageClass = StorageClass;
            request_x.AWSAccessKeyId = AWSAccessKeyId;
            request_x.Timestamp = Timestamp;
            request_x.Signature = Signature;
            request_x.Credential = Credential;
            Map<String, S3.PutObjectInlineResponse_element> response_map_x = new Map<String, S3.PutObjectInlineResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'PutObjectInline',
              'http://s3.amazonaws.com/doc/2006-03-01/',
              'PutObjectInlineResponse',
              'S3.PutObjectInlineResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.PutObjectInlineResponse;
        }
        
          
          
        /*
           This method invokes the S3 SetObjectAccessControlPolicy web service operation.
        */
        public Boolean SetObjectAccessControlPolicy(String Bucket,String Key,String accessType,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential, String canonicalUserId){
        	
        
        	 //S3Request S3XMLSoapRequest=  new S3Request('SetObjectAccessControlPolicy');
            S3Request S3XMLSoapRequest=  new S3Request();
            S3XMLSoapRequest.soapBody= '<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Header/><env:Body>';
            S3XMLSoapRequest.soapBody+= '<SetObjectAccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/">';
            S3XMLSoapRequest.soapBody += '<Bucket>' + Bucket + '</Bucket>';
            S3XMLSoapRequest.soapBody += '<Key>' + Key + '</Key>';
            S3XMLSoapRequest.soapBody += '<AccessControlList><Grant><Grantee xsi:type="CanonicalUser"><ID>'+canonicalUserId+'</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant><Grant><Grantee xsi:type="Group"><URI>http://acs.amazonaws.com/groups/global/AllUsers</URI></Grantee><Permission>READ</Permission></Grant></AccessControlList>';
            S3XMLSoapRequest.soapBody +='<AWSAccessKeyId>' + AWSAccessKeyId + '</AWSAccessKeyId>';
            String formattednow = Timestamp.formatGmt('yyyy-MM-dd')+'T'+Timestamp.formatGmt('HH:mm:ss')+'.'+Timestamp.formatGMT('SSS')+'Z';
            S3XMLSoapRequest.soapBody += '<Timestamp>' + formattednow + '</Timestamp>';
            S3XMLSoapRequest.soapBody += '<Signature>' + signature + '</Signature>';
            S3XMLSoapRequest.soapBody +='<Credential>' + credential + '</Credential>';
            
            S3XMLSoapRequest.soapBody +='</SetObjectAccessControlPolicy></env:Body></env:Envelope>';
            
	        System.debug('SOAP REQUEST BODY: ' + S3XMLSoapRequest.soapBody);
	        httpresponse res = S3XMLSoapRequest.makeRequest();
	        System.debug('SOAP RESPONSE: ' + res.getBody());
	        AWS_XMLDom dom = new AWS_XMLDom( res.getBody() ); 
	        dom.dumpAll();
	         
            if(dom.getElementsByTagName('Description')!=null){
              System.debug('Successfully uploaded file with SetObjectAccessControlPolicy method');
              return true;	
            }
            else{
            	System.debug('Error: Failed to uploaded file with SetObjectAccessControlPolicy method');
              return false;
            }
            
       
           	
           	
        }
          
        /*
              This method uses the S3 SOAP API to upload an object to the specified bucket and apply an Access Policy.  
        */  
        public Boolean PutObjectInline_ACL(String Bucket,String Key,S3.MetadataEntry[] Metadata,String Data,Integer ContentLength,String accessType,String AWSAccessKeyId,DateTime Timestamp,String Signature,String Credential, String canonicalUserId) {
             
            //S3Request S3XMLSoapRequest=  new S3Request('PutObjectInline');
            S3Request S3XMLSoapRequest=  new S3Request();
            
            S3XMLSoapRequest.soapBody= '<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Header/><env:Body>';
            S3XMLSoapRequest.soapBody+= '<PutObjectInline xmlns="http://s3.amazonaws.com/doc/2006-03-01/">';
            S3XMLSoapRequest.soapBody += '<Bucket>' + Bucket + '</Bucket>';
            S3XMLSoapRequest.soapBody += '<Key>' + Key + '</Key>';
            
            
            if(Metadata!=null){
	            for(S3.MetadataEntry entry: Metadata)
	               S3XMLSoapRequest.soapBody += '<Metadata><Name>'+entry.Name+'</Name><Value>'+entry.Value+'</Value></Metadata>';
            }
            
            S3XMLSoapRequest.soapBody += '<Data>' + Data + '</Data>';
            S3XMLSoapRequest.soapBody += '<ContentLength>' +  String.valueOf(ContentLength) + '</ContentLength>';
            S3XMLSoapRequest.soapBody += '<AccessControlList>';
            
            if(accessType=='public-read')
            	S3XMLSoapRequest.soapBody += '<Grant><Grantee xsi:type="Group"><URI>http://acs.amazonaws.com/groups/global/AllUsers</URI></Grantee><Permission>READ</Permission></Grant>';
            if(accesstype=='public-write')
               S3XMLSoapRequest.soapBody += '<Grant><Grantee xsi:type="Group"><URI>http://acs.amazonaws.com/groups/global/AllUsers</URI></Grantee><Permission>WRITE</Permission></Grant>';
            
            //Default Owner to FULL_CONTROL
            system.assert(canonicalUserId!=null);
            S3XMLSoapRequest.soapBody += '<Grant><Grantee xsi:type="CanonicalUser"><ID>'+canonicalUserId+'</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant>';
            
            S3XMLSoapRequest.soapBody += '</AccessControlList>';
            S3XMLSoapRequest.soapBody +='<AWSAccessKeyId>' + AWSAccessKeyId + '</AWSAccessKeyId>';
            String formattednow = Timestamp.formatGmt('yyyy-MM-dd')+'T'+Timestamp.formatGmt('HH:mm:ss')+'.'+Timestamp.formatGMT('SSS')+'Z';
            S3XMLSoapRequest.soapBody += '<Timestamp>' + formattednow + '</Timestamp>';
            S3XMLSoapRequest.soapBody += '<Signature>' + signature + '</Signature>';
            S3XMLSoapRequest.soapBody +='<Credential>' + credential + '</Credential>';
            S3XMLSoapRequest.soapBody +='</PutObjectInline></env:Body></env:Envelope>';
            
             
	        System.debug('SOAP REQUEST BODY: ' + S3XMLSoapRequest.soapBody);
	        httpresponse res = S3XMLSoapRequest.makeRequest();
	        System.debug('SOAP RESPONSE: ' + res.getBody());
	        AWS_XMLDom dom = new AWS_XMLDom( res.getBody() ); 
	        dom.dumpAll();
	         
            if(dom.getElementsByTagName('LastModified')!=null){
              System.debug('Successfully uploaded file with PutObjectInline_ACL method');
              return true;	
            }
            else{
            	System.debug('Error: Failed to uploaded file with PutObjectInline_ACL method');
              return false;
            }
            
       
        
        }
        
    }
    
    /*
    public class GetBucketLoggingStatus_element {
        public String Bucket;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','AWSAccessKeyId','Timestamp','Signature','Credential'};
    }
    public class GetObjectExtended_element {
        public String Bucket;
        public String Key;
        public Boolean GetMetadata;
        public Boolean GetData;
        public Boolean InlineData;
        public Double ByteRangeStart;
        public Double ByteRangeEnd;
        public DateTime IfModifiedSince;
        public DateTime IfUnmodifiedSince;
        public String[] IfMatch;
        public String[] IfNoneMatch;
        public Boolean ReturnCompleteObjectOnConditionFailure;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Key_type_info = new String[]{'Key','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] GetMetadata_type_info = new String[]{'GetMetadata','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
        private String[] GetData_type_info = new String[]{'GetData','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
        private String[] InlineData_type_info = new String[]{'InlineData','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
        private String[] ByteRangeStart_type_info = new String[]{'ByteRangeStart','http://www.w3.org/2001/XMLSchema','long','0','1','false'};
        private String[] ByteRangeEnd_type_info = new String[]{'ByteRangeEnd','http://www.w3.org/2001/XMLSchema','long','0','1','false'};
        private String[] IfModifiedSince_type_info = new String[]{'IfModifiedSince','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] IfUnmodifiedSince_type_info = new String[]{'IfUnmodifiedSince','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] IfMatch_type_info = new String[]{'IfMatch','http://www.w3.org/2001/XMLSchema','string','0','100','false'};
        private String[] IfNoneMatch_type_info = new String[]{'IfNoneMatch','http://www.w3.org/2001/XMLSchema','string','0','100','false'};
        private String[] ReturnCompleteObjectOnConditionFailure_type_info = new String[]{'ReturnCompleteObjectOnConditionFailure','http://www.w3.org/2001/XMLSchema','boolean','0','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','Key','GetMetadata','GetData','InlineData','ByteRangeStart','ByteRangeEnd','IfModifiedSince','IfUnmodifiedSince','IfMatch','IfNoneMatch','ReturnCompleteObjectOnConditionFailure','AWSAccessKeyId','Timestamp','Signature','Credential'};
    }
    public class PostResponse_element {
        public String Location;
        public String Bucket;
        public String Key;
        public String ETag;
        private String[] Location_type_info = new String[]{'Location','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Key_type_info = new String[]{'Key','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] ETag_type_info = new String[]{'ETag','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Location','Bucket','Key','ETag'};
    }
    public class GetBucketAccessControlPolicy_element {
        public String Bucket;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','AWSAccessKeyId','Timestamp','Signature','Credential'};
    }
    */
    public class ListAllMyBucketsEntry {
        public String Name { get; set; }
        public DateTime CreationDate;
        private String[] Name_type_info = new String[]{'Name','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] CreationDate_type_info = new String[]{'CreationDate','http://www.w3.org/2001/XMLSchema','dateTime','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Name','CreationDate'};
    }
    public class CreateBucketResult {
        public String BucketName;
        private String[] BucketName_type_info = new String[]{'BucketName','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'BucketName'};
    }
    public class ListEntry {
        public String Key {get;set;}
        public DateTime LastModified {get;set;}
        public String ETag {get;set;}
        public Double Size {get;set;}
        public S3.CanonicalUser Owner {get;set;}
        public String StorageClass {get;set;}
        private String[] Key_type_info = new String[]{'Key','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] LastModified_type_info = new String[]{'LastModified','http://www.w3.org/2001/XMLSchema','dateTime','1','1','false'};
        private String[] ETag_type_info = new String[]{'ETag','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Size_type_info = new String[]{'Size','http://www.w3.org/2001/XMLSchema','long','1','1','false'};
        private String[] Owner_type_info = new String[]{'Owner','http://s3.amazonaws.com/doc/2006-03-01/','CanonicalUser','0','1','false'};
        private String[] StorageClass_type_info = new String[]{'StorageClass','http://s3.amazonaws.com/doc/2006-03-01/','StorageClass','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Key','LastModified','ETag','Size','Owner','StorageClass'};
    }
    
    
    public class PutObjectInlineResponse_element {
        public S3.PutObjectResult PutObjectInlineResponse;
        private String[] PutObjectInlineResponse_type_info = new String[]{'PutObjectInlineResponse','http://s3.amazonaws.com/doc/2006-03-01/','PutObjectResult','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'PutObjectInlineResponse'};
    }
    
    public class DeleteObject_element {
        public String Bucket;
        public String Key;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Key_type_info = new String[]{'Key','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','Key','AWSAccessKeyId','Timestamp','Signature','Credential'};
    }
    public class ListAllMyBucketsResult {
        public S3.CanonicalUser Owner;
        public S3.ListAllMyBucketsList Buckets { get; set; }
        private String[] Owner_type_info = new String[]{'Owner','http://s3.amazonaws.com/doc/2006-03-01/','CanonicalUser','1','1','false'};
        private String[] Buckets_type_info = new String[]{'Buckets','http://s3.amazonaws.com/doc/2006-03-01/','ListAllMyBucketsList','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Owner','Buckets'};
    }
    public class ListAllMyBucketsResponse_element {
        public S3.ListAllMyBucketsResult ListAllMyBucketsResponse;
        private String[] ListAllMyBucketsResponse_type_info = new String[]{'ListAllMyBucketsResponse','http://s3.amazonaws.com/doc/2006-03-01/','ListAllMyBucketsResult','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'ListAllMyBucketsResponse'};
    }
    
    /*
    public class GetObjectExtendedResponse_element {
        public S3.GetObjectResult GetObjectResponse;
        private String[] GetObjectResponse_type_info = new String[]{'GetObjectResponse','http://s3.amazonaws.com/doc/2006-03-01/','GetObjectResult','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'GetObjectResponse'};
    }
    
    */
    
    
    public class CreateBucketResponse_element {
        public S3.CreateBucketResult CreateBucketResponse;
        private String[] CreateBucketResponse_type_info = new String[]{'CreateBucketResponse','http://s3.amazonaws.com/doc/2006-03-01/','CreateBucketResponse','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'CreateBucketResonse'};
    }
    public class Status {
        public Integer Code {get;set;}
        public String Description {get;set;}
        private String[] Code_type_info = new String[]{'Code','http://www.w3.org/2001/XMLSchema','int','1','1','false'};
        private String[] Description_type_info = new String[]{'Description','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Code','Description'};
    }
    public class DeleteBucket_element {
        public String Bucket;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','AWSAccessKeyId','Timestamp','Signature','Credential'};
    }
    
    /*
    public class SetObjectAccessControlPolicy_element {
        public String Bucket;
        public String Key;
        public S3.AccessControlList AccessControlList;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Key_type_info = new String[]{'Key','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] AccessControlList_type_info = new String[]{'AccessControlList','http://s3.amazonaws.com/doc/2006-03-01/','AccessControlList','1','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','Key','AccessControlList','AWSAccessKeyId','Timestamp','Signature','Credential'};
    }
    public class GetObjectAccessControlPolicyResponse_element {
        public S3.AccessControlPolicy GetObjectAccessControlPolicyResponse;
        private String[] GetObjectAccessControlPolicyResponse_type_info = new String[]{'GetObjectAccessControlPolicyResponse','http://s3.amazonaws.com/doc/2006-03-01/','AccessControlPolicy','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'GetObjectAccessControlPolicyResponse'};
    }
    public class SetBucketLoggingStatus_element {
        public String Bucket;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        public S3.BucketLoggingStatus BucketLoggingStatus;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] BucketLoggingStatus_type_info = new String[]{'BucketLoggingStatus','http://s3.amazonaws.com/doc/2006-03-01/','BucketLoggingStatus','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','AWSAccessKeyId','Timestamp','Signature','Credential','BucketLoggingStatus'};
    }
    
    */
    
    public class PrefixEntry {
        public String Prefix;
        private String[] Prefix_type_info = new String[]{'Prefix','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Prefix'};
    }
    
    public class DeleteObjectResponse_element {
        public S3.Status DeleteObjectResponse;
        private String[] DeleteObjectResponse_type_info = new String[]{'DeleteObjectResponse','http://s3.amazonaws.com/doc/2006-03-01/','Status','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'DeleteObjectResponse'};
    }
    
    /*
    public class SetBucketAccessControlPolicy_element {
        public String Bucket;
        public S3.AccessControlList AccessControlList;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] AccessControlList_type_info = new String[]{'AccessControlList','http://s3.amazonaws.com/doc/2006-03-01/','AccessControlList','0','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','AccessControlList','AWSAccessKeyId','Timestamp','Signature','Credential'};
    }
    public class GetBucketLoggingStatusResponse_element {
        public S3.BucketLoggingStatus GetBucketLoggingStatusResponse;
        private String[] GetBucketLoggingStatusResponse_type_info = new String[]{'GetBucketLoggingStatusResponse','http://s3.amazonaws.com/doc/2006-03-01/','BucketLoggingStatus','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'GetBucketLoggingStatusResponse'};
    }
    */
    public class ListAllMyBuckets_element {
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'AWSAccessKeyId','Timestamp','Signature'};
    }
    
    /*
    public class SetBucketLoggingStatusResponse_element {
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{};
    }
    */
    public class PutObjectResult {
        public String ETag;
        public DateTime LastModified;
        private String[] ETag_type_info = new String[]{'ETag','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] LastModified_type_info = new String[]{'LastModified','http://www.w3.org/2001/XMLSchema','dateTime','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'ETag','LastModified'};
    }
    
    /*
    public class GetObjectAccessControlPolicy_element {
        public String Bucket;
        public String Key;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Key_type_info = new String[]{'Key','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','Key','AWSAccessKeyId','Timestamp','Signature','Credential'};
    }
    public class BucketLoggingStatus {
        public S3.LoggingSettings LoggingEnabled;
        private String[] LoggingEnabled_type_info = new String[]{'LoggingEnabled','http://s3.amazonaws.com/doc/2006-03-01/','LoggingSettings','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'LoggingEnabled'};
    }
    public class GetObject_element {
        public String Bucket;
        public String Key;
        public Boolean GetMetadata;
        public Boolean GetData;
        public Boolean InlineData;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Key_type_info = new String[]{'Key','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] GetMetadata_type_info = new String[]{'GetMetadata','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
        private String[] GetData_type_info = new String[]{'GetData','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
        private String[] InlineData_type_info = new String[]{'InlineData','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','Key','GetMetadata','GetData','InlineData','AWSAccessKeyId','Timestamp','Signature','Credential'};
    }
    public class Group_x extends Grantee {
        public String URI;
        private String[] URI_type_info = new String[]{'URI','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'URI'};
    }
    */
    public class AccessControlList {
        //public S3.Grant[] Grant;
        private String[] Grant_type_info = new String[]{'Grant','http://s3.amazonaws.com/doc/2006-03-01/','Grant','0','100','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Grant'};
    }
    
    /*
    abstract class  Grantee {
    	//public String URI;
    	//private String[] URI_type_info = new String[]{'URI','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        //private String[] field_order_type_info = new String[]{'URI'};
        private String[] field_order_type_info = new String[]{};
    }
    public class CopyObjectResponse_element {
        public S3.CopyObjectResult CopyObjectResult;
        private String[] CopyObjectResult_type_info = new String[]{'CopyObjectResult','http://s3.amazonaws.com/doc/2006-03-01/','CopyObjectResult','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'CopyObjectResult'};
    }
    */
    public class CanonicalUser {
        public String ID;
        public String DisplayName;
        private String[] ID_type_info = new String[]{'ID','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] DisplayName_type_info = new String[]{'DisplayName','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'ID','DisplayName'};
    }
    
    /*
    public class Result {
        public S3.Status Status;
        private String[] Status_type_info = new String[]{'Status','http://s3.amazonaws.com/doc/2006-03-01/','Status','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Status'};
    }
    public class AmazonCustomerByEmail {
        public String EmailAddress;
        private String[] EmailAddress_type_info = new String[]{'EmailAddress','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'EmailAddress'};
    }
    public class PutObjectResponse_element {
        public S3.PutObjectResult PutObjectResponse;
        private String[] PutObjectResponse_type_info = new String[]{'PutObjectResponse','http://s3.amazonaws.com/doc/2006-03-01/','PutObjectResult','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'PutObjectResponse'};
    }
    public class SetObjectAccessControlPolicyResponse_element {
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{};
    }
    public class User_x {
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{};
    }
    
    */
    
    public class ListBucket_element {
        public String Bucket;
        public String Prefix;
        public String Marker;
        public Integer MaxKeys;
        public String Delimiter;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Prefix_type_info = new String[]{'Prefix','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Marker_type_info = new String[]{'Marker','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] MaxKeys_type_info = new String[]{'MaxKeys','http://www.w3.org/2001/XMLSchema','int','0','1','false'};
        private String[] Delimiter_type_info = new String[]{'Delimiter','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','Prefix','Marker','MaxKeys','Delimiter','AWSAccessKeyId','Timestamp','Signature','Credential'};
    }
    
    
    /*
    public class GetObjectResult {
        public S3.MetadataEntry[] Metadata;
        public String Data;
        public DateTime LastModified;
        public String ETag;
        private String[] Metadata_type_info = new String[]{'Metadata','http://s3.amazonaws.com/doc/2006-03-01/','MetadataEntry','0','-1','false'};
        private String[] Data_type_info = new String[]{'Data','http://www.w3.org/2001/XMLSchema','base64Binary','1','1','true'};
        private String[] LastModified_type_info = new String[]{'LastModified','http://www.w3.org/2001/XMLSchema','dateTime','1','1','false'};
        private String[] ETag_type_info = new String[]{'ETag','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Metadata','Data','LastModified','ETag'};
    }
    */
    public class PutObjectInline_element {
        public String Bucket;
        public String Key;
        public S3.MetadataEntry[] Metadata;
        public String Data;
        public Integer ContentLength;
        public S3.AccessControlList AccessControlList;
        public String StorageClass;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Key_type_info = new String[]{'Key','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Metadata_type_info = new String[]{'Metadata','http://s3.amazonaws.com/doc/2006-03-01/','MetadataEntry','0','100','false'};
        private String[] Data_type_info = new String[]{'Data','http://www.w3.org/2001/XMLSchema','base64Binary','1','1','false'};
        private String[] ContentLength_type_info = new String[]{'ContentLength','http://www.w3.org/2001/XMLSchema','long','1','1','false'};
        private String[] AccessControlList_type_info = new String[]{'AccessControlList','http://s3.amazonaws.com/doc/2006-03-01/','AccessControlList','0','1','false'};
        private String[] StorageClass_type_info = new String[]{'StorageClass','http://s3.amazonaws.com/doc/2006-03-01/','StorageClass','0','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','Key','Metadata','Data','ContentLength','AccessControlList','StorageClass','AWSAccessKeyId','Timestamp','Signature','Credential'};
    }
    /*
    public class LocationConstraint {
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{};
    }
    public class CopyObject_element {
        public String SourceBucket;
        public String SourceKey;
        public String DestinationBucket;
        public String DestinationKey;
        public String MetadataDirective;
        public S3.MetadataEntry[] Metadata;
        public S3.AccessControlList AccessControlList;
        public DateTime CopySourceIfModifiedSince;
        public DateTime CopySourceIfUnmodifiedSince;
        public String[] CopySourceIfMatch;
        public String[] CopySourceIfNoneMatch;
        public String StorageClass;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        private String[] SourceBucket_type_info = new String[]{'SourceBucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] SourceKey_type_info = new String[]{'SourceKey','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] DestinationBucket_type_info = new String[]{'DestinationBucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] DestinationKey_type_info = new String[]{'DestinationKey','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] MetadataDirective_type_info = new String[]{'MetadataDirective','http://s3.amazonaws.com/doc/2006-03-01/','MetadataDirective','0','1','false'};
        private String[] Metadata_type_info = new String[]{'Metadata','http://s3.amazonaws.com/doc/2006-03-01/','MetadataEntry','0','100','false'};
        private String[] AccessControlList_type_info = new String[]{'AccessControlList','http://s3.amazonaws.com/doc/2006-03-01/','AccessControlList','0','1','false'};
        private String[] CopySourceIfModifiedSince_type_info = new String[]{'CopySourceIfModifiedSince','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] CopySourceIfUnmodifiedSince_type_info = new String[]{'CopySourceIfUnmodifiedSince','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] CopySourceIfMatch_type_info = new String[]{'CopySourceIfMatch','http://www.w3.org/2001/XMLSchema','string','0','100','false'};
        private String[] CopySourceIfNoneMatch_type_info = new String[]{'CopySourceIfNoneMatch','http://www.w3.org/2001/XMLSchema','string','0','100','false'};
        private String[] StorageClass_type_info = new String[]{'StorageClass','http://s3.amazonaws.com/doc/2006-03-01/','StorageClass','0','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'SourceBucket','SourceKey','DestinationBucket','DestinationKey','MetadataDirective','Metadata','AccessControlList','CopySourceIfModifiedSince','CopySourceIfUnmodifiedSince','CopySourceIfMatch','CopySourceIfNoneMatch','StorageClass','AWSAccessKeyId','Timestamp','Signature','Credential'};
    }
    */
    public class CreateBucket_element {
        public String Bucket;
        public S3.AccessControlList AccessControlList;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] AccessControlList_type_info = new String[]{'AccessControlList','http://s3.amazonaws.com/doc/2006-03-01/','AccessControlList','0','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','AccessControlList','AWSAccessKeyId','Timestamp','Signature'};
    }
    
    /*
    public class PutObject_element {
        public String Bucket;
        public String Key;
        public S3.MetadataEntry[] Metadata;
        public Double ContentLength;
        public S3.AccessControlList AccessControlList;
        public String StorageClass;
        public String AWSAccessKeyId;
        public DateTime Timestamp;
        public String Signature;
        public String Credential;
        private String[] Bucket_type_info = new String[]{'Bucket','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Key_type_info = new String[]{'Key','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] Metadata_type_info = new String[]{'Metadata','http://s3.amazonaws.com/doc/2006-03-01/','MetadataEntry','0','100','false'};
        private String[] ContentLength_type_info = new String[]{'ContentLength','http://www.w3.org/2001/XMLSchema','long','1','1','false'};
        private String[] AccessControlList_type_info = new String[]{'AccessControlList','http://s3.amazonaws.com/doc/2006-03-01/','AccessControlList','0','1','false'};
        private String[] StorageClass_type_info = new String[]{'StorageClass','http://s3.amazonaws.com/doc/2006-03-01/','StorageClass','0','1','false'};
        private String[] AWSAccessKeyId_type_info = new String[]{'AWSAccessKeyId','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Timestamp_type_info = new String[]{'Timestamp','http://www.w3.org/2001/XMLSchema','dateTime','0','1','false'};
        private String[] Signature_type_info = new String[]{'Signature','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] Credential_type_info = new String[]{'Credential','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Bucket','Key','Metadata','ContentLength','AccessControlList','StorageClass','AWSAccessKeyId','Timestamp','Signature','Credential'};
    }
    public class AccessControlPolicy {
        public S3.CanonicalUser Owner;
        public S3.AccessControlList AccessControlList;
        private String[] Owner_type_info = new String[]{'Owner','http://s3.amazonaws.com/doc/2006-03-01/','CanonicalUser','1','1','false'};
        private String[] AccessControlList_type_info = new String[]{'AccessControlList','http://s3.amazonaws.com/doc/2006-03-01/','AccessControlList','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'Owner','AccessControlList'};
    }
    public class CreateBucketConfiguration {
        public S3.LocationConstraint LocationConstraint;
        private String[] LocationConstraint_type_info = new String[]{'LocationConstraint','http://s3.amazonaws.com/doc/2006-03-01/','LocationConstraint','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'LocationConstraint'};
    }
    */
    public class DeleteBucketResponse_element {
        public S3.Status DeleteBucketResponse;
        private String[] DeleteBucketResponse_type_info = new String[]{'DeleteBucketResponse','http://s3.amazonaws.com/doc/2006-03-01/','Status','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{'DeleteBucketResponse'};
    }
    
    /*
    public class SetBucketAccessControlPolicyResponse_element {
        private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'};
        private String[] field_order_type_info = new String[]{};
    }
    
    */
    
    
    /*
      This class uses the HTTP Request apex class to transmit the SOAP request to Amazon. 
      The SOAP XML is set on the public variable, soapBody, and the proper HTTP Headers are set. 
      Then the data is sent to Amazon and the response is returned to the calling method (if successful)
    */
    public class S3Request {
	
		// data class used to construct a request to AWS S3
	 	public AWS_XMLDom.element body = new AWS_XMLDom.element('env:Body');
		public string soapBody { get ; set;} 
		 
		 //default constructor
		public S3Request() { 
		}
		
		
		
		transient HttpResponse response = null;
		public string error {get;set;}
	    public HttpResponse makeRequest()  { // leaves result in res instance member
	        error = null;
	        HttpRequest req = new HttpRequest();   
	        req.setEndpoint('https://s3.amazonaws.com/soap');
	        
	        
	        req.setMethod('POST'); 
	        //req.setCompressed(true); // otherwise we hit a limit of 32000   
	        /* avoid getting more than we can process on the callout
	         * max is 32000, more will throw an exception from the server
	         * we could go back for a second range, but this will give ~10 normal blog entries
	         */
	        //req.setHeader('Range','bytes=0-50000');  // not all feeds respect this
	        
	        System.debug('before soap body: ' + soapBody);
	        //String bodyString = soapBody.replace( '&','&amp;');
			//bodyString = bodyString.replace('\n','');
			//bodyString = bodyString.replace(' ','');
			
			//bodyString = '<?xml version="1.0" encoding="UTF-8"?>'+bodyString;
	        
	        //bodyString = bodyString.replace(' >','>');
	        
	        System.debug('after soap body: ' + soapBody);
	        req.setBody(soapBody);
	        
	        
	        //if ( this.debug > 1 ) system.debug(req);
	        //if ( this.debug > 2 ) system.debug(body);
	        req.setHeader('Content-Type', 'application/soap+xml' );
	        req.setHeader('SOAPAction','');
			System.debug('content length: ' + string.valueof(soapBody.trim().length()));
	        req.setHeader('Content-Length',string.valueof(soapBody.trim().length()));
	        
	        try {
	            Http http = new Http();
	            System.debug('making S3 request...: ' + req);
	            response = http.send(req);
	            if (response.getStatusCode() != 200 ) {
	                
	                System.debug('STATUS:'+response.getStatus());
	                System.debug('STATUS_CODE:'+response.getStatusCode());
	                System.debug('BODY: '+response.getBody());
	                AWS_XMLDom dom = new AWS_XMLDom( response.getBody() );
		 			dom.dumpAll();
		 			if ( response.getStatusCode() == 500 ) {
		 				string reasonPath = '';  
		 				AWS_XMLDom.element e = dom.getElementByPath('/.*/Fault') ;
		 				if ( e!= null ) {
		 					e.dumpAll();
		 					error = body + response.getBody() ;//+ '\n'+e.getValue('Text');
		 				} else { 
		 					system.debug( 'no fault found' ); 
		 				}
		 				
		 			}
	            } 
	            
	        } catch( System.Exception e) {
	            System.debug('ERROR: '+ e);
	        }
	        return response;
	    }
	    
	    
    
}
    
 
   /* Below are all the test methods required to deploy this apex code and meet the Test Method Code Coverage requirements of the Force.com platform
   */ 
    
   public static testmethod void test1() {
   	 	s3.ListBucketResponse_element lbre = new s3.ListBucketResponse_element();
   	 	s3.ListBucketResult lbr = new s3.ListBucketResult();
   	 	s3.ListAllMyBucketsList lambl = new s3.ListAllMyBucketsList();
   		s3.metadataEntry me = new s3.metadataEntry();
		s3.ListAllMyBucketsEntry lambe = new s3.ListAllMyBucketsEntry();   
   		s3.ListAllMyBucketsResult lambr = new s3.ListAllMyBucketsResult();
   		s3.CreateBucketResult cbr = new s3.CreateBucketResult();
   		s3.listEntry le = new s3.listEntry();
   		s3.DeleteObject_element  doe = new s3.DeleteObject_element();
   		s3.CanonicalUser co = new s3.CanonicalUser();
   		s3.DeleteBucketResponse_element dbr = new s3.DeleteBucketResponse_element();
   		s3.PrefixEntry pe = new s3.PrefixEntry();
   		s3.status status = new s3.status();
   		s3.ListAllMyBucketsResponse_element labre = new s3.ListAllMyBucketsResponse_element();
   		s3.CreateBucketResponse_element cbre = new s3.CreateBucketResponse_element();
   		
   		S3.AmazonS3 sss = new S3.AmazonS3(); 
   		
   	 	sss.DeleteObject( '','','',system.now(),'','');
   
   }
   
    public static testmethod void test2() {
    	S3.AmazonS3 sss = new S3.AmazonS3();
    	sss.secret = '42';
    	system.assert( sss.signature('encode',system.now() ) != null);
    	sss.ListBucket( '','','', 3,'','key',system.now(),'sig','cred'); 	
    }
 
    public static testmethod void test3() {
    	S3.AmazonS3 S3 = new S3.AmazonS3();
    	S3.secret = '42';
    	system.assert( S3.signature('encode',system.now() ) != null);
    	S3.ListAllMyBuckets('key',system.now(),'sig');
    }  
   
    public static testmethod void test4() {
    	S3.AmazonS3 S3 = new S3.AmazonS3();
    	S3.secret = '42';
    	system.assert( S3.signature('encode',system.now() ) != null);
    	s3.AccessControlList acl = new s3.AccessControlList();
    	S3.CreateBucket('bucket',acl,'key',system.now(),'sig');
    }  
   
    public static testmethod void test5() {
    	S3.AmazonS3 S3 = new S3.AmazonS3();
    	S3.secret = '42';
    	system.assert( S3.signature('encode',system.now() ) != null);
    	S3.DeleteBucket('bucket','key',system.now(),'sig','cred');
    }  
    
    public static testmethod void test6(){
       S3.AmazonS3 S3 = new S3.AmazonS3();
       S3.PutObjectInline_element putObjectElem = new S3.PutObjectInline_element();
       putObjectElem.Bucket='test';
       putObjectElem.Key = 'testKey';
       putObjectElem.Metadata = null;
       putObjectElem.Data= 'a';
       putObjectElem.ContentLength = 1;
       putObjectElem.AccessControlList = null;
       putObjectElem.StorageClass='classname';
       putObjectElem.AWSAccessKeyId='asdf';
       putObjectElem.Timestamp = Datetime.now();
       putObjectElem.Signature='test';
       putObjectElem.Credential='test';	
    }
  
    public static testmethod void test7(){
    
      S3.AmazonS3 S3 = new S3.AmazonS3();
      S3.secret = '42';
      system.assert( S3.signature('encode',system.now() ) != null);
      try{
      S3.PutObjectInline_ACL('bucket','key',null,'datatesting',6,'public-read','keyid',System.now(),'sig','cred', 'ownerid') ;
      }catch(Exception ex){
      }
    }
    
}